package com.zxc.judgeservice.message;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class InintRabbitMq {
    public static void init() {
        try {

            ConnectionFactory connectionFactory = new ConnectionFactory();
            connectionFactory.setHost("localhost");
            Connection connection = connectionFactory.newConnection();
            Channel channel = connection.createChannel();
            String exchangeName = "code_exchange";
            channel.exchangeDeclare(exchangeName, "direct");
            String queueName = "code_queue";
            channel.queueDeclare(queueName, true, false, false, null);
            channel.queueBind(queueName, exchangeName, "routingKey");
            log.info("消息队列初始化完成");
        } catch (Exception e) {
            log.error("消息队列初始化失败");
        }
    }


}
